<?php
/**
 * 会员登录相关
 * @author fanzhanao
 *
 */
class member_controller_login extends SnsController{
	var $data = '';
//	var $right_view = true;
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
		$this->data	 =	Model::factory('member_model_data');
		$this->frameView = VIEW_PATH.'/index.phtml';
	}
	
	/**
     * @return 用户登录
     */
    public function login_action(){
    	$username = _('username');
    	$pwd	=	_('pwd');
    	$to	=	_('to')?_('to'):'http://www.'.DOMAIN;
    	$always	=	_('autologin');
    	/**
    	 * 判断是否已经登录，则跳转
    	 */
    	if(self::$login['uid']){
    		if($to){
    			self::responseJs(null,$to,false);
    		}else{
    			$this->_redirect($this->app,'index','index',array('uid'=>self::$login['uid']),true);
    		}
    	}
    	
    	/*if(vcode_get2(Cache::getInstance(), 'vcode')!=strtoupper(_('vcode'))){
			self::responseJs('验证码不正确',null,true);
		}else{
			Plugin::vcode_clean();
		}*/
		
    	if($username && $pwd){
    		$rs = $this->data->login($username,$pwd,$always);
    		if($rs ){
//    			file_put_contents(LOG_PATH.'/login.log',serialize($rs)."\r\n",FILE_APPEND);
    			if(is_numeric($rs)){
    				self::responseJs('您的用户名或者密码错误，请重新登录！',null,true);
    			}else{
    				/**
             		 * 更新最后登录时间
             		 */
    				if($rs['uid']){
    					$args['uid'] = $rs['uid'];
    					$args['last_login']    =   CURRENT_TIME;
    					$this->data->edit($args,$rs['uid']);
    				}

    				if($to){
    					self::_renderRedirect($to);
    				}
					else $this->_redirect($this->app,'index','index',array('uid'=>$rs['uid']),true);
    			}
    		}
    	}
    	
		$this->view = 'part_login_left';
		$this->right_view	=	'/index/part_login_right.phtml';
    }
    
    /**
     * 退出登录
     *
     */
    public function logout_action(){
    	$to = _('to')?_('to'):'http://www.'.DOMAIN;
    	if(self::$login['uid']){
    		member_util_login::logout();
    	}
    	self::responseJs(null,$to,false);
    }

    public function rr_login_action(){	
        $this->_renderJson();
        $_rruid = _('rruid');
        
    }

	
}
?>